﻿using AutoMapper;
using BS.Infra;
using BS.Infra.Interface;
using BS.Write.Api.Handler.SlaughterEnter;
using MediatR;

namespace BS.Read.Api.Handler.SlaughterEnter
{
    public class ShowSEHandler : IRequestHandler<GetSlaughterEnterListRequestDTO, ApiResult>
    {
        private readonly ISlaughterEnterpriseRepository _slaughterEnterpriseRepository;

        private readonly IMapper _mapper;

        private readonly ILogger<ShowSEHandler> _logger;

        public ShowSEHandler(ISlaughterEnterpriseRepository slaughterEnterpriseRepository, IMapper mapper, ILogger<ShowSEHandler> logger)
        {
            _slaughterEnterpriseRepository = slaughterEnterpriseRepository;
            _mapper = mapper;
            _logger = logger;
        }
        public async Task<ApiResult> Handle(GetSlaughterEnterListRequestDTO request, CancellationToken cancellationToken)
        {
            try
            {
                var se = await _slaughterEnterpriseRepository.GetAllAsync(x=>x.IsDeleted==false);
                
                return ApiResult.Ok(data:se);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error in ShowSEHandler");
                return ApiResult.Ok(ex.Message);
            }
        }
    }
}
public class GetSlaughterEnterListRequestDTO:IRequest<ApiResult>
{

}
public class GetSlaughterEnterListReponseDTO
{
    public int CompanyId { get; set; }
    /// <summary>
    /// 公司名称
    /// </summary>
    public string CompanyName { get; set; } = string.Empty;
    /// <summary>
    /// 成立日期
    /// </summary>
    public DateTime EstablishDate { get; set; }
    /// <summary>
    /// 公司地址（三级联动）
    /// </summary>
    public int AddressId { get; set; }
    /// <summary>
    /// 公司简介
    /// </summary>
    public string CompanyProfile { get; set; } = string.Empty;
}